package com.alexfu.countdownview.sample.slice;

import com.alexfu.countdownview.CountDownListener;
import com.alexfu.countdownview.CountDownView;
import com.alexfu.countdownview.sample.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Text;
import ohos.agp.text.Font;
import ohos.agp.window.dialog.ToastDialog;

/**
 * MainAbilitySlice
 *
 * @since 2021-07-02
 */
public class MainAbilitySlice extends AbilitySlice implements CountDownListener {
    private CountDownView countDownView;
    private Button startButton;
    private Button resetButton;
    private Button stopButton;
    private Text text;

    /**
     * onStart
     *
     * @param intent intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        text = (Text) findComponentById(ResourceTable.Id_tv_title);
        countDownView = (CountDownView) findComponentById(ResourceTable.Id_view_count_down);
        startButton = (Button) findComponentById(ResourceTable.Id_button_start);
        resetButton = (Button) findComponentById(ResourceTable.Id_button_reset);
        stopButton = (Button) findComponentById(ResourceTable.Id_button_stop);
        text.setFont(Font.DEFAULT_BOLD);
        countDownView.setListener(this);
        startButton.setClickedListener(component -> {
            countDownView.start();
        });
        resetButton.setClickedListener(component -> countDownView.reset());
        stopButton.setClickedListener(component -> countDownView.stop());
    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     * onForeground
     *
     * @param intent intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    /**
     *  onFinishCountDown
     */
    @Override
    public void onFinishCountDown() {
        ToastViewDialog.toastDialog(this,"Time up !!!");
    }

}
